home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / ged-e / ec21b_compile.rexx < prev    next >
OS/2 REXX Batch file  |  1994-10-10  |  16KB  |  437 lines

  1. /* $VER: 2.0, ©1994 BURGHARD Eric.                            */
  2.  
  3. --8<--------- Cut this Speed up RexxMast Processing a little ---------------
  4.  
  5.    Compile current file using EC2.1b ,EPP1.4d and MAC2E4.0 if it must
  6.    Errors, Warnings, Auto-Revision, Compile to disk,
  7.    Run arguments, EC arguments are handled.
  8.    File notification mechanism to avoid useless compilation
  9.    EC,EPP,Mac2E must be located on EDEVICE:
  10.    EC,EPP,Mac2E are put in RAM: on first use.
  11.    A directory E/ is make in T:
  12.  
  13.  VARIABLES:
  14.  ----------
  15.    Environnement vars set: (name stand for "your E Source name")
  16.               ENV:ECOpt    : ECompiler args (see EC docs)
  17.               T:E/name.opt : Executable args
  18.               T:E/name.mcf : Macros Files
  19.               T:E/name.mcp : Macros Path
  20.  
  21.    GED boolean vars set:
  22.               USER1  : Compile to disk
  23.               USER2  : Replace Macros (Mac2E)
  24.               USER3  : Auto-Revision
  25.               USER4  : Warnings
  26.  
  27.  NOTEZ BIEN:  Errors handling depends on EPP or EC errors output,
  28.  -----------   So you may have to modify this script if you use
  29.                other version than 2.1b|3.0 for EC, 1.4d for EPP,
  30.               and 4.0 for Mac2E.
  31.  
  32.  BUGS:        Perhaps Not all EPP1.4d are handled.
  33.  -----        Folowing EC errors messages are not handled
  34.                 - 'not enought memory while (re-)allocating'
  35.                 - 'reference(s) out of 32k: switch to LARGE model'
  36.                 - 'reference(s) out of 256k'
  37.                 because EC2.1b don't return an error code. So you
  38.                 may have an error from this script like, 'can not
  39.                 rename ''filename1' as 'filename2'': object not find
  40.                 cause EC didn't generate executable file and didn't
  41.                 released an error code. So View T:Eerror to know the
  42.                 reason of the failure.
  43.               As EC2.1b didn't release DOS warning code, i must
  44.                 parse t:Eerror to find them: Currently handled warning
  45.                 messages are the ones beginning with 'UNREFERENCED'
  46.                 or 'WARNING' in T:Eerror. This could change for another
  47.                 version of EC then 2.1b.
  48.               Autorevision processing is space sensitive; check that
  49.                 parenthesis are present in string requester of GUI config
  50.                 panel; i could normally do it in this script but i can not
  51.                 succed. Autorevision force files to be always compiled
  52.                 because source are always 'modified'.
  53.  
  54. ---------------------------------------------------------------------------
  55. */
  56.  
  57. options results                             /* enable return codes     */
  58.                                             /* not started by GoldEd ? */
  59. if (LEFT(ADDRESS(), 6) ~= "GOLDED") then address 'GOLDED.1'
  60. 'LOCK CURRENT QUIET'                        /* lock GUI, gain access   */
  61. if rc then exit
  62. options failat 6                            /* ignore warnings         */
  63. signal on syntax                            /* ensure clean exit       */
  64.  
  65. 'QUERY FILE PATH USER1 ANYTEXT'
  66. parse var result name ' ' path ' ' optcdisk ' ' anytext
  67.  
  68. if (anytext=="TRUE") then do
  69.   if (upper(right(name,2)))='.E' then do
  70.     if right(path,1)~=":" then path=''path'/'
  71.     if ~exists("T:E") then address command 'Makedir T:E'
  72.     oldname=name
  73.     name=left(name,length(name)-2)
  74.     if optcdisk="TRUE" then do
  75.       name=''path''name''
  76.     end
  77.     else name='T:E/'name''
  78.     nameo=name
  79.     'QUERY MODIFY ABAK LINE COLUMN FIND'
  80.     parse var result modify ' ' backup ' ' olne ' ' col ' ' fstr
  81.     exist=exists(name)
  82.     if (optcdisk="TRUE") then do
  83.       'MISC AUTOBAK="TRUE"'
  84.       if modify="TRUE" then 'SAVE ALL NAME 'nameo'.e'
  85.     end
  86.     else do
  87.       'MISC AUTOBAK="FALSE"'
  88.       if (~exist | modify="TRUE") then 'SAVE ALL NAME 'nameo'.e'
  89.     end
  90.     'MISC AUTOBAK="'backup'"'
  91.     if exist then do
  92.       'NOTIFY FILE 'path''oldname' CHECK'
  93.       notify=result
  94.       if rc=5 then do
  95.         'NOTIFY FILE 'path''oldname' START'
  96.         notify=1
  97.       end
  98.     end
  99.     else notify=1
  100.     if (~exist | (exist & (modify="TRUE" | (modify="FALSE" & notify~=0)))) then do
  101.       call Compile
  102.       if ~exist then 'NOTIFY FILE 'path''oldname' START'
  103.     end
  104.     else do
  105.       'REQUEST BODY="File have already been compiled !" BUTTON="ReCompile|Run|Cancel"'
  106.       if result=1 then do
  107.         call Compile
  108.       end
  109.       else if result=2 then do
  110.         cmd=''
  111.         call Execute
  112.       end
  113.     end
  114.     'FIND STRING="'fstr'" FIRST QUIET'
  115.     'GOTO LINE='olne' COLUMN='col''
  116.   end
  117.   else 'REQUEST STATUS=" E Sources names must end with '.e'"'
  118. end
  119. else 'REQUEST STATUS=" Text buffer is empty ?!"'
  120. 'UNLOCK'
  121. exit
  122.  
  123. Compile:
  124.    /* ----------------------- Modules processing ------------------------ */
  125.     load = 0                                /* Bool for right source error pos */
  126.     'FIND STRING="PMODULE " FIRST QUIET'
  127.     IF (rc==0) THEN DO
  128.        if ~exists("ram:epp") then address command 'copy EDEVICE:EPP RAM:'
  129.        errhdlr = 2                          /* Bool for Error processing */
  130.        load = 1                             /* Bool for right source error pos */
  131.        'REQUEST STATUS=" Linking current source with extern modules ..."'
  132.        signal on error
  133.        address command 'RAM:Epp >T:Eerror -n 'name' 'nameo'_lnk'
  134.        signal off error
  135.        name=''nameo'_lnk'
  136.     end
  137.     'FIND STRING="'fstr'" FIRST QUIET COUNT' /* Replace old FIND string */
  138.     'GOTO LINE='olne' COLUMN='col''
  139.  
  140.     /* ------------------------ Macros processing ------------------------ */
  141.     if right(oldname,6)~="_mac.e" then do     /* Don't compile Mac2E outputs */
  142.       'QUERY USER2'
  143.       if result=="TRUE" then do
  144.         load=1                               /* Bool for right source error pos */
  145.         if ~exists("ram:MAC2E") then address command 'copy EDEVICE:MAC2E RAM:'
  146.         if ~exists("T:E") then address command 'Makedir T:E'
  147.         optname=left(oldname,length(oldname)-2)
  148.         macfile='T:E/'optname'.mcf'
  149.         macpath='T:E/'optname'.mcp'
  150.         if ~exists(macpath) then do
  151.           ok=open(fhandle,macpath,"write")
  152.           ok=writeln(fhandle,"EDEVICE:PreAnalyzedMacroFiles")
  153.           ok=close(fhandle)
  154.         end
  155.         if exists(macfile) then do
  156.           ok=open(fhandle,macfile,"read")
  157.           macname=readln(fhandle)
  158.           ok=close(fhandle)
  159.         end
  160.         else do
  161.           address command 'EDEVICE:RtRequest 'macfile' 'macpath' TITLE="Select macros definitions files" EXIST'
  162.           if rc~=0 then do
  163.             'NAME 'path''oldname''
  164.             'REQUEST STATUS=" You must specifie a macros definitions file !"'
  165.             'UNLOCK'
  166.             exit
  167.           end
  168.           else do
  169.             ok=open(fhandle,macfile,"read")
  170.             macname=readln(fhandle)
  171.             ok=close(fhandle)
  172.           end
  173.         end
  174.         errhdlr=1
  175.         'REQUEST STATUS=" Begining macro remplacement ..."'
  176.         signal on error
  177.         address command 'RAM:Mac2E >T:Eerror 'name'.e 'nameo'_mac.e 'macname''
  178.         signal off error
  179.         'REQUEST STATUS=""'
  180.         name=''nameo'_mac'                    /* Source Name for Next tools */
  181.       end
  182.     end
  183.  
  184.     /* --------------------- Compilation processing ---------------------- */
  185.     if ~exists("ram:EC30b") then address command 'copy EDEVICE:EC30b RAM:'
  186.     if exists("ENV:ECOpt") then do
  187.       ok=open(readhandle,"ENV:ECOpt","read")
  188.       optec=readln(readhandle)
  189.       ok=close(readhandle)
  190.     end
  191.     else optec=""
  192.     errhdlr = 0                                /* Bool for Error processing */
  193.     'REQUEST STATUS=" Compiling in process ..."'
  194.     signal on error
  195.     address command 'RAM:EC30b >T:Eerror 'optec' 'name''
  196.     signal off error
  197.     if name~=nameo then do                     /* Name of final executable */
  198.       if exists(nameo) then address command 'Delete 'nameo' QUIET'
  199.       address command 'Rename 'name' 'nameo' QUIET'
  200.     end
  201.     'REQUEST STATUS=""'
  202.  
  203.     /* ----------------------- Version processing ------------------------ */
  204.     if (modify==TRUE|notify~=0) then do
  205.       'QUERY USER3'
  206.       if (result==TRUE) then do
  207.         'PING SLOT=0'                               /* save cursor position */
  208.         'MARK HIDE'                                    /* no blocks, please */
  209.         'QUERY FIND VAR SPAT'                          /* remember settings */
  210.         'QUERY USECASE VAR USECASE'
  211.         'FIND STRING="''$VER:" FIRST CASE=TRUE QUIET'  /* search version id */
  212.         if (rc==0) then do                                      /* found ?? */
  213.           'QUERY BUFFER'            /* what is the line we are over now ?  */
  214.           parse var result '$VER: ' vername ' ' version '.' revision ' ('
  215.           revision=revision+1
  216.           if (revision<10) then revision='00'revision''
  217.           else if (revision<100) then revision='0'revision''
  218.           'NEXT'
  219.           'NEXT'
  220.           'DELETE WORD'                   /* delete old revision string */
  221.           'DEL'
  222.           'DELETE WORD'
  223.           'DEL'
  224.           'DELETE WORD'
  225.           'DEL'
  226.           'DELETE WORD'
  227.           'DEL'
  228.           'TEXT T="'version'.'revision' ('date()') "'                  /* insert new into the text */
  229.         end
  230.         else do
  231.           'FIND STRING=main() CASE=TRUE FIRST QUIET'
  232.           if (rc==0) then do
  233.             'FOLD OPEN=TRUE'
  234.             'FIND STRING=ENDPROC CASE=TRUE NEXT'
  235.             'QUERY ABSLINE VAR LNE'
  236.             'DOWN'
  237.             'QUERY ABSLINE'
  238.             if (result==lne) then do
  239.               'GOTO EOL'
  240.               'CR'
  241.             end
  242.             else do
  243.               'FIRST'
  244.               'QUERY WORD'
  245.               if result='/*FEND*/' then do
  246.                 'QUERY ABSLINE VAR LNE'
  247.                 'DOWN'
  248.                 'QUERY ABSLINE'
  249.                 if (result==lne) then do
  250.                   'GOTO EOL'
  251.                   'CR'
  252.                 end
  253.               end
  254.             end
  255.           end
  256.           else do
  257.             'GOTO BOTTOM'
  258.             'GOTO EOL'
  259.             'CR'
  260.           end
  261.           'QUERY FILE VAR FILE'
  262.           file=left(file,length(file)-2)
  263.           'TEXT T="CHAR ''$VER: 'file' 1.000 ('date()') © BURGHARD Eric | WANABOSO/AGOA''" CR'
  264.           'FOLD ALL OPEN=FALSE'
  265.         end
  266.         'PONG SLOT=0'
  267.         'FIND STRING="'spat'" CASE='usecase''
  268.       end
  269.     end
  270.  
  271.     /* ------------------- Warning Message processing -------------------- */
  272.     'QUERY USER4'
  273.     if result='TRUE' then do
  274.       ok = open(filehandler,'T:Eerror','Read')
  275.       if ok = 0 then 'REQUEST STATUS=" Could not read E Compiler error output"'
  276.       else do
  277.         reqmsg=''
  278.         do until eof(filehandler)
  279.           line  = readln(filehandler)
  280.           pos=index(line,'UNREFERENCED')
  281.           if pos~=0 then do
  282.             reqmsg=substr(line,pos,length(line)-pos+1)
  283.             do while ~eof(filehandler)
  284.               line=readln(filehandler)
  285.               pos=index(line,'WARNING')
  286.               if pos~=0 then reqmsg=''reqmsg'|'substr(line,pos,length(line)-pos+1)''
  287.             end
  288.           end
  289.           else do
  290.             pos=index(line,'WARNING')
  291.             if pos~=0 then reqmsg=substr(line,pos,length(line)-pos+1)
  292.           end
  293.         end
  294.         if reqmsg~='' then do
  295.            reqmsg=compress(reqmsg,'"')
  296.           'REQUEST TITLE="ECompiler warning message..." BODY="'reqmsg'"'
  297.         end
  298.         ok = close(filehandler)
  299.       end
  300.     end
  301.     cmd='REQUEST BODY="Compilation Done ! Run program ?" BUTTON="_run|_cancel"'
  302.  
  303. Execute:
  304.     /* ---------------------------- Execute ------------------------------ */
  305.     if optcdisk=='FALSE' then 'NAME NEW 'path''oldname''  /* restore old file name */
  306.     'FIND STRING="OPT MODULE" FIRST QUIET'
  307.     if (rc~=0) then do
  308.       result=1
  309.       if cmd~='' then cmd
  310.       if (result == 1) then do
  311.         'REQUEST STATUS=" 'nameo' is running"'
  312.         if Exists('T:E/'oldname'.opt') then do
  313.           optname=left(oldname,length(oldname)-2)
  314.           ok = open(filehandle,'T:E/'optname'.opt',"read")
  315.           runopt=readln(filehandle)
  316.           ok = close(filehandle)
  317.         end
  318.         else runopt=""
  319.         options failat 100
  320.         address command ''nameo' 'runopt''
  321.         options failat 10
  322.       end
  323.       'REQUEST STATUS=""'
  324.     end
  325.     else 'REQUEST STATUS=" Module correctly generated"'
  326.     return
  327.  
  328.    /* ---------------------- Errors processing ------------------------ */
  329. error:
  330.   signal off error                              /* Avoid looping problems */
  331.   'REQUEST STATUS=""'
  332.   if optcdisk=='FALSE' then 'NAME NEW 'path''oldname''  /* restore old file name */
  333.   ok = open(filehandler,'T:Eerror','Read')
  334. select
  335.  
  336.   when errhdlr = 0 then do
  337.     'REQUEST STATUS=""'                       /* EC Error Handler      */
  338.     if optcdisk=='FALSE' then 'NAME NEW 'oldname''  /* restore old file name */
  339.     ok = open(filehandler,'T:Eerror','Read')
  340.     if ok = 0 then 'REQUEST STATUS="Could not read E Compiler error output"'
  341.     else do
  342.       linestring=''
  343.       withstring=''
  344.       errorstring=''
  345.       errortext=''
  346.       line=readln(filehandler)
  347.       do while ~eof(filehandler)
  348.         line  = readln(filehandler)
  349.         select
  350.         when index(line,'ERROR:')~=0 then do
  351.           parse var line 'ERROR: ' errorstring
  352.           errorstring=strip(errorstring)
  353.           parse var errorstring left '"' right
  354.         end
  355.         when find(line,'WITH:')~=0 then do
  356.           parse var line 'WITH: ' withstring
  357.           withstring=strip(withstring)
  358.           parse var withstring left '"' right
  359.         end
  360.         when find(line,'LINE ')~=0 then do
  361.           parse var line 'LINE ' errorline ': ' linestring '/*'
  362.           linestring=strip(linestring,L)
  363.           linestring=left(linestring,64)
  364.           linestring=strip(linestring)
  365.           parse var linestring left '"' right
  366.         end
  367.         otherwise nop
  368.         end
  369.       end
  370.       errortext='Line 'errorline''
  371.       if linestring~='' then errortext=''errortext': 'linestring''
  372.       if errorstring~='' then errortext=''errortext'|Error: 'errorstring''
  373.       if withstring~='' then errortext=''errortext'|With : 'withstring''
  374.       if load=1 then 'OPEN NEW NAME="'name'.e"'
  375.       'GOTO LINE='errorline''
  376.       errortext=compress(errortext,'"')
  377.       'REQUEST TITLE="ECompiler 2.1b error" BODY="'errortext'"'
  378.       ok = close(filehandler)
  379.       'UNLOCK'
  380.       exit
  381.     end
  382.   end
  383.  
  384.   when errhdlr=1 then do                     /* MAC2E Error Handler */
  385.     if ok = 0 then 'REQUEST STATUS=" Could not read Mac2E error output"'
  386.     else do
  387.       do 3                                   /* Jump Mac2E HeadLines     */
  388.         line = readln(filehandler)
  389.       end
  390.       do while ~eof(filehandler)
  391.         line = readln(filehandler)
  392.         if index(line,'...')==0 then do
  393.           parse var line line '!'
  394.           errortext=compress(errortext,'"')
  395.           'REQUEST TITLE="Mac2E 4.0 error" BODY="'line'"'
  396.           ok = close(filehandler)
  397.           'UNLOCK'
  398.           exit
  399.         end
  400.       end
  401.     end
  402.   end
  403.  
  404.   when errhdlr = 2 then do                  /* EPP Error handler     */
  405.     'REQUEST STATUS=""'
  406.     if optcdisk=='FALSE' then 'NAME NEW 'oldname''  /* restore old file name */
  407.     ok = open(filehandler,'T:Eerror','Read')
  408.     if ok = 0 then 'REQUEST STATUS="Could not read EPP error output"'
  409.     else do
  410.       errorstring=''
  411.       errortext=''
  412.       do while ~eof(filehandler)
  413.         line = readln(filehandler)
  414.         if index(line,'***')~=0 then parse var line "***" errorstring ": " errortext
  415.       end
  416.       errortext=''errorstring' ERROR WITH 'errortext''
  417.       'REQUEST TITLE="EPP error message..." BODY="'errortext'"'
  418.       ok = close(filehandler)
  419.       'UNLOCK'
  420.       exit 0
  421.     end
  422.   end
  423.  
  424.   otherwise nop
  425.  
  426. end
  427.  
  428. ok = close(filehandler)
  429. 'UNLOCK'
  430. exit
  431.  
  432. syntax:
  433. say "Sorry, error line" SIGL ":" ERRORTEXT(RC) ":-("
  434. 'UNLOCK'
  435. exit
  436.  
  437.